package com.heisenhub.system.controller;


import com.heisenhub.common.db.controller.AbstractController;
import com.heisenhub.system.dto.MenuDto;
import com.heisenhub.system.entity.Menu;
import com.heisenhub.system.enums.SystemEnums;
import com.heisenhub.system.query.MenuQuery;
import com.heisenhub.system.service.IMenuService;
import com.heisnenhub.common.module.inter.BusinessTypeEnumsInter;
import com.heisnenhub.common.module.utils.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author sen
 * @since 2023-12-24
 */
@RestController
@RequestMapping("/menu")
public class MenuController extends AbstractController<Menu, MenuDto, MenuQuery, IMenuService> {


    /**
     * 获取动态路由
     *
     * @param username
     * @return
     */
    @GetMapping("/routerUserMeta")
    public Api routerUserMeta(String username) {
        return Api.ok(service.getUserRouters(username));
    }


    /**
     * 获取所有树状菜单 and 按钮
     */
    @GetMapping("/findTreeAllMetaView")
    @PreAuthorize("hasAnyAuthority('menu:view')")
    public Api findTreeAllMetaView() {
        return Api.ok(service.findTreeAllMetaView(null));
    }


    /**
     * 获取所有树状菜单
     */
    @GetMapping("/findTreeByMenusaView")
    @PreAuthorize("hasAnyAuthority('menu:view')")
    public Api findTreeByMenusaView() {
        return Api.ok(service.findTreeByMenusaView());
    }


    @Override
    public BusinessTypeEnumsInter getBusinessTypeEnums() {
        return SystemEnums.MENUS;
    }
}
